package com.kitty.game.safeLock;

import com.kitty.game.role.model.Role;
import com.kitty.common.utils.SpringUtils;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.game.safeLock.service.SafeService;
import org.apache.mina.core.session.IoSession;
import org.springframework.stereotype.Controller;
import com.kitty.game.safeLock.message.ReqModifyPasswd;
import com.kitty.game.safeLock.message.ReqOpenSafeLockDlg;
import com.kitty.game.safeLock.message.ReqRestPasswd;
import com.kitty.game.safeLock.message.ReqSetSafePasswd;
import com.kitty.game.safeLock.message.ReqUnlock;

@Controller
public class SafeLockController {

    /**
     * 打开加锁
     */
    @RequestMapping
    public void openSafeLockDlg(IoSession session, ReqOpenSafeLockDlg reqOpenSafeLockDlg) {
        SpringUtils.getBean(SafeService.class).openSafeDlg(session, reqOpenSafeLockDlg);

    }

    /**
     * 设置密码
     */
    @RequestMapping
    public void setSafePasswd(IoSession session, ReqSetSafePasswd reqSetSafePasswd) {
        SpringUtils.getBean(SafeService.class).setSafePasswd(session, reqSetSafePasswd);
    }

    /**
     * 验证解锁
     */
    @RequestMapping
    public void unlock(IoSession session, ReqUnlock reqUnlock) {
        SpringUtils.getBean(SafeService.class).unlock(session, reqUnlock);
    }

    /**
     * 修改密码
     */
    @RequestMapping
    public void modifyPasswd(IoSession session, ReqModifyPasswd reqModifyPasswd) {
        SpringUtils.getBean(SafeService.class).modifyPasswd(session, reqModifyPasswd);
    }

    /**
     * 重置密码
     */
    @RequestMapping
    public void restPasswd(IoSession session, ReqRestPasswd reqRestPasswd) {
        Role role = SessionUtils.getRoleBySession(session);
        switch (reqRestPasswd.getFlag()) {
            case 1:
                /**申请重置*/
                SpringUtils.getBean(SafeService.class).reqReset(role);
                break;
            case 0:
                /**取消申请重置*/
                SpringUtils.getBean(SafeService.class).cancelReset(role);
                break;
        }
    }
}
